#include "HTNLinkQueue.h"

bool HTNLinkQueue::isEmpty()
{
	if (this->head->next==nullptr && this->length==0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

int HTNLinkQueue::getLength()
{
	return this->length;
}

HTNLinkQueue::HTNLinkQueue()
{
	this->head = new HTNLinkNode();
	this->length = 0;
}

HTNode* HTNLinkQueue::getTop()
{
	if (this->isEmpty())
	{
		return nullptr;
	}
	return this->head->next->data;
}

HTNode* HTNLinkQueue::getEnd()
{
	if (this->isEmpty())
	{
		return nullptr;
	}
	HTNLinkNode* p = this->head->next;
	while (p->next!=nullptr)
	{
		p = p->next;
	}
	return p->data;
}


HTNLinkQueue::~HTNLinkQueue()
{
	HTNLinkNode* p, * pre;
	p = this->head;
	pre = p->next;
	while (pre!=nullptr)
	{
		delete p;
		p = pre;
		pre = pre->next;
	}
	delete p;
}

void HTNLinkQueue::enQueue(HTNode* e)
{
	HTNLinkNode* s = this->head;
	while (s->next!=nullptr)
	{
		s = s->next;
	}
	HTNLinkNode* p = new HTNLinkNode(e);
	s->next = p;
	this->length++;
}

HTNode* HTNLinkQueue::deQueue()
{
	if (this->isEmpty())
	{
		return nullptr;
	}
	HTNode* c;
	c = this->head->next->data;
	HTNLinkNode* p = this->head->next;
	this->head->next = p->next;
	delete p;
	this->length--;
	return c;
}
